package com.unicom.office.builder;

import com.unicom.office.config.OfficeConfig;
import com.unicom.office.runtime.OfficeRuntime;
import com.unicom.office.unit.*;

public abstract class DocumentBuilder extends OfficeBuilder {
    public DocumentBuilder() {
        super(null, null);
    }

    public DocumentBuilder(OfficeConfig config, OfficeRuntime runtime) {
        super(config, runtime);
    }

    public Object build2(OfficeUnit unit, Object parent){
        Object result = null;
        if(unit instanceof DocumentUnit) {
            result = buildDocument((DocumentUnit)unit);
        }else if(unit instanceof SectionUnit) {
            result = buildSection((SectionUnit)unit, parent);
        }else if(unit instanceof DocTableUnit) {
            result = buildDocTable((DocTableUnit)unit, parent);
        }else if(unit instanceof RowUnit){
            result = buildRow((RowUnit)unit, parent);
        }else if(unit instanceof CellUnit){
            result = buildCell((CellUnit)unit, parent);
        }else if(unit instanceof ParagraphUnit){
            result = buildParagraph((ParagraphUnit) unit, parent);
        }else if(unit instanceof TextRangeUnit){
            result = buildTextrange((TextRangeUnit) unit, parent);
        }else if(unit instanceof PictureUnit){
            result = buildPicture((PictureUnit) unit, parent);
        }else if(unit instanceof TextboxUnit){
            result = buildTextbox((TextboxUnit)unit, parent);
        }else {
            throw new RuntimeException("无法构建的节点");
        }

        return result;
    }

    protected abstract Object buildDocument(DocumentUnit unit);
    protected abstract Object buildSection(SectionUnit unit, Object parent);
    protected abstract Object buildDocTable(DocTableUnit unit, Object parent);
}
